<?php

namespace App\Http\Controllers\XhApi;


use App\Repository\XhApi\AddressRepository;
use Illuminate\Http\Request;

class AddressController extends BaseController
{
    public $repoist;

    public function __construct()
    {
        $this->repoist = new AddressRepository();
    }

    public function regions(Request $request)
    {
        $data = file_get_contents(resource_path() . '/regions.json');
        $data = json_decode($data, true);
        return $this->returnMsg(200, '查询成功', $data);
    }

    public function index(Request $request)
    {
        $params = $request->all();
        $params['member_id'] = $params['user']['id'];
        //拉修改资料
        if (isset($params['id']) && $params['id'] > 0) {
            $row = $this->repoist->unifiedGetOne(['id' => $params['id'], 'member_id' => $params['member_id']]);
            return $this->returnMsg(200, '查询成功', $row);
        }
        return $this->repoist->index($params, $request->get('pageNum'), 30);
    }

    public function add(Request $request)
    {
        return $this->repoist->add($request->all(), $request->user->id);
    }

    public function edit(Request $request)
    {
        return $this->repoist->edit($request->all(), $request->user->id);
    }
}
